//
//  IManager+ModuleDiscount.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-6-25.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "IManager+ModuleDiscount.h"
#import "NSString+NSString_Ex_.h"
#import "FrameworkRelativeDefines.h"
#import "NetUrlDefines.h"
#import "RequestUtlity.h"
#import "RCDiscountDataModel.h"

@implementation IManager(ModuleDiscount)

-(int64_t)requestDiscountInfo:(NSString *)cityID Pn:(NSInteger)pn Rn:(NSInteger)rn Longitude:(NSString *)lon Latitude:(NSString *)latitude Type:(DiscountType)type withDelegate:(id<IManagerDelegate>)delegate{
    if ([NSString stringIsNullOrEmpty:cityID]) {
        return kInvalidRequestId;
    }
    BOOL isValidOfMap = [NSString stringIsNullOrEmpty:lon] || [NSString stringIsNullOrEmpty:latitude] || ([lon floatValue] == 0.0 && [latitude floatValue] == 0.0);
    if (isValidOfMap) {
        return kInvalidRequestId;
    }
    if (rn == 0) {
        rn = 15;
    }
    
    CGFloat map_x = [lon floatValue];
    CGFloat map_y = [latitude floatValue];
    map_y = 39.97252;
    map_x = 116.332161;
    // 异步获取数据
    NSString *urlSuffix = [NSString stringWithFormat:kRCDiscountUrlPrefix,cityID,pn,rn,map_y,map_x,type];
    NSString *url = [RequestUtlity getFormattedUrl:urlSuffix];
    
    KFLog(@"request url %@",url);
    return [[IDataProvider sharedInstance] asyncFetchDataWithUserInfo:url
                                                             userInfo:nil
                                                      withCachePolicy:IDataCachePolicyLocalFileAndNetwork
                                                   withDataParseClass:[RCDiscountDataModel class]
                                                     withDataDelegate:delegate];
}

@end
